PORT	EQU	#EF
BUFER	EQU	#C000
FONT	EQU	48000
;
	ORG	#8000
;
START
	EXX
	PUSH	HL
	EXX
;
	LD	HL,(#5C3D)
	LD	(SAV_ERRSP),HL
	LD	(BASIC_SP),SP
	CALL	SET_CHAN
	LD	IX,DATA
FOR_OFF_LOGO
	CALL	LOGO
OK_AND_MENU
	LD	IX,DATA
	CALL	PRINT_MENU
OK_RET
	LD	IX,DATA
	CALL	MAIN
	LD	A,#C9
	LD	(#5CC2),A
	CALL	SET_CHAN
	LD	HL,#5D0F
	LD	A,(HL)
	LD	(HL),0
	CP	20
	JR	Z,ALL_ERROR
	ADD	A,#80
	CP	#80
	JR	NZ,ALL_ERROR
	LD	A,(IY)
ALL_ERROR
	CP	#FE
	JR	Z,OK_AND_MENU
	OR	A
	JP	Z,UE_ERR
	LD	HL,ERR_MESS
	LD	BC,LEN_EM
	CPIR
	LD	A,C
	OR	B
	JR	NZ,NORM_ERROR
UE_ERR
	LD	HL,UE_MESS
NORM_ERROR
	LD	A,(TTY_X)
	OR	A
	LD	A,13
	CALL	NZ,#10
	CALL	OUTLI1
	JR	OK_RET
ERR_MESS
	DEFB	0
UE_MESS
	DEFB	"Fatal error",0
	DEFB	255,"Ok",0
	DEFB	3,"No memory",0
	DEFB	20,"Break",0
	DEFB	26,"Disk error",0
;
	DEFB	#81,"No	file",0
	DEFB	#83,"No	memory",0
	DEFB	#86,"No	disk",0
	DEFB	#87,"Disk error",0
	DEFB	#8B,"No	file",0
;
	DEFB	#A0,"Memory overflow",0
;
LEN_EM	EQU	$-ERR_MESS
;
PRINT_ADR
	DEFW	CHPUT
;
CHPUT	PUSH	AF
	PUSH	IX
	LD	IX,DATA
	CP	#0C
	JR	Z,CH_CLS
	CP	#0D
	JR	Z,CH_CR
	CP	" "
	JR	C,CH_NOPRT
	CALL	OUTCH
CH_TST	LD	A,(TTY_Y)
	CP	24
	JR	Z,CH_ROL
CH_END	LD	A,(TTY_Y)
	LD	(IX+CSRY),A
	LD	A,(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1
C94
	PUSH	AF
	CALL	OUTLI1
	POP	AF
	JR	C9E1
MS_R	DEFB	" Retry",13,0
MS_I	DEFB	" Ignore",13,0
MS_A	DEFB	" Abort",13,0
;
SET_CHAN
	PUSH	HL
	LD	HL,PRINT_ADR
	LD	(#5C51),HL
	POP	HL
	RET
;
MAIN
	LD	(IY),#FF
	LD	(IY+48),0
	LD	(#5C3D),SP
	JP	KEY_CHECK
;
I_KEYS
	DEFB	"H"
	DEFW	HELP
	DEFB	"L"
	DEFW	LOGGED
	DEFB	"A"
	DEFW	AUTO
	DEFB	"Q"
	DEFW	C_QUIT
	DEFB	"C"
	DEFW	C_CAT
	DEFB	"F"
	DEFW	LOAD_FONT
	DEFB	"B"
	DEFW	C_BAUD
	DEFB	"P"
	DEFW	C_PARITY
	DEFB	"D"
	DEFW	C_DEVICE
	DEFB	"T"
	DEFW	C_TRANSMIT
	DEFB	"R"
	DEFW	C_RECEIVE
	DEFB	"S"
	DEFW	C_TEST
;
LIKEYS	EQU	12
;
HELP
	CALL	OUTLIN
	DEFB	#0C,13
	DEFB	"This version support ZX-MODEM by",13
	DEFB	"Victor	Morohovsky: (0572)352249",13
	DEFB	"If you	want take new version of this",13
	DEFB	"program then call me: (0572)529733",13
	DEFB	"This program is shareware...",13,13
	DEFB	"Interface ZX-LPRINT III.",13,13
	DEFB	"For BREAK receive press <SPACE>.",13
	DEFB	"For CANCEL input addresses or",13
	DEFB	"filenames press <ENTER>.",13
	DEFB	"Black border -	transmit or receive",13
	DEFB	"block.",13,13,0
	RET
C_TEST
	CALL	OUTLIN
	DEFB	"Testing phone line...",13,0
	LD	HL,0
	LD	(TR_ST),HL
	LD	HL,50
	LD	(TR_END),HL
	CALL	TRANSMIT
	RET
;
C_RECEIVE
	LD	A,(SDEV)
	AND	A
	JP	Z,RECE_DISC
	CP	1
	JP	Z,RECE_MEM
	CP	2
	JP	Z,RECE_SCR
	CALL	OUTLIN
	DEFB	"Receive to printer.",13,0
	LD	A,(23296)
	CP	95
	JP	NZ,NOTREADY
	CALL	OUTLIN
	DEFB	"You have interface ZX-LPRINT III",13
	DEFB	"Connect printer and press a key for ready."
	DEFB	13,0
CONTR1
	CALL	KBD
	LD	HL,BUFER_SCR
	LD	DE,BUFER_SCR+1
	LD	BC,63
	LD	(HL)," "
	LDIR
	LD	HL,BUFER_SCR
	AND	A
	CALL	RECEIVE
	JP	Z,BREAK2
	LD	A,B
	OR	C
	CALL	NZ,ERSCR
	LD	A,3
CHAN	EQU	$-1
	CALL	#1601
	CALL	PRINTBUF
	LD	A,2
	LD	(CHAN),A
	CALL	#1601
	RET
;
NOTREADY
	CALL	OUTLIN
	DEFB	"Interface not ready.",13,0
	RET
;
RECE_DISC
	CALL	OUTLIN
	DEFB	"Receive to disc.",13
	DEFB	"Press a key for ready.",13
	DEFB	0
	CALL	KBD
	AND	A
	LD	HL,BUFER_SCR
	CALL	RECEIVE
	LD	A,H
	OR	L
	JP	Z,BREAK2
;	JP	Z,BREAK2
	LD	HL,BUFER_SCR
	LD	DE,BBB2
	LD	BC,8
	LDIR
	LD	A,(BUFER_SCR+8)
	LD	(BBB3),A
	LD	A,(BUFER_SCR+13)
	LD	L,A
	LD	H,0
	PUSH	IX
	LD	IX,BUFDEC
	CALL	PRIDEC
	POP	IX
	LD	HL,(BUFDEC+3)
	LD	(BBB4),HL
	CALL	OUTLIN
	DEFB	13
	DEFB	"Receive file: "
BBB2	DEFB	"	  ."
BBB3	DEFB	" "
	DEFB	" Length: "
BBB4	DEFB	"  "
	DEFB	" sector(s).",13
	DEFB	"Please	Wait.",13,0
	LD	A,(BUFER_SCR+13)
	LD	(MANYSEC1),A
	LD	(MANY2),A
	LD	A,1
	LD	(COUNNUM1),A
	LD	A,16
	LD	(HOW21),A
	LD	A,#40
	LD	(HOW11),A
	LD	C,5
	CALL	SEC8
	LD	HL,(BUFER+225)	 ;!!!
	LD	(#5CF4),HL
LOOPTR1
	CALL	CLS_BUF
	LD	A,0
MANYSEC1 EQU	 $-1
	AND	A
	JP	Z,END_TR1
	CP	64
	JP	C,OST
	SUB	64
	LD	(MANYSEC1),A
CONTLOA1
	LD	B,16
HOW21	EQU	$-1
REPTR1
	PUSH	BC
;
	LD	HL,BUFER
BUFCOU1	EQU	$-2
	PUSH	HL
	LD	DE,1024
	ADD	HL,DE
	LD	(BUFCOU1),HL
	POP	HL
	AND	A
	CALL	RECEIVE
	JP	Z,EX_L
;
	LD	A,0
COUNNUM1 EQU	 $-1
	LD	L,A
	LD	H,0
	PUSH	AF
	PUSH	IX
	LD	IX,BUFDEC
	CALL	PRIDEC
	POP	IX
	POP	AF
	INC	A
	LD	(COUNNUM1),A
	LD	HL,(BUFDEC+3)
	LD	(BBBB),HL
	LD	A,23
	LD	(SCROLL_CNT),A
	CALL	OUTLIN
	DEFB	"Block #"
BBBB	DEFB	"  "
	DEFB	" receiving.",13,0
	POP	BC
	DJNZ	REPTR1
;
	LD	BC,#4006
HOW11	EQU	$-1
	LD	HL,BUFER
	LD	(BUFCOU1),HL
	LD	DE,(#5CF4)
	CALL	DOS
	JP	LOOPTR1
OST1
	LD	(HOW11),A
	SRL	A
	JR	NC,COST11
	INC	A
COST11
	SRL	A
	JR	NC,COST3
	INC	A
COST3
	LD	(HOW21),A
	XOR	A
	LD	(MANYSEC1),A
	CALL	CLS_BUF
	JP	CONTLOA1
;
END_TR1
	LD	C,5
	CALL	SEC8
	LD	HL,(#5CF4)
	LD	(BUFER+225),HL	;!!!
	LD	HL,(BUFER+229)
	LD	DE,0
MANY2	EQU	$-2
	ADD	HL,DE
	LD	(BUFER+229),HL
	LD	HL,BUFER+228
	LD	A,(HL)
	INC	(HL)
	LD	HL,BUFER_SCR
	LD	DE,#5CDD
	LD	BC,16
	LDIR
	LD	C,9
	CALL	DOS
	LD	C,6
	CALL	SEC8
;
	CALL	OUTLIN
	DEFB	"End of	receive.",13,0
	RET
SEC8
	LD	HL,BUFER
	LD	DE,#0008
	LD	B,1
	CALL	DOS
	RET
;
RECE_MEM
	CALL	OUTLIN
	DEFB	"Receive from addr: ",0
	CALL	READNU
	RET	Z
	CALL	CONDEC
	PUSH	HL
	CALL	OUTLIN
	DEFB	13
	DEFB	"Press a key for ready.",13,0
	CALL	KBD
	POP	HL
	AND	A
	CALL	RECEIVE
	JP	Z,BREAK2
	LD	A,H
	OR	L
	JP	Z,RBREAK
	PUSH	IX
	PUSH	BC
	LD	IX,REC_B
	CALL	PRIDEC
	POP	HL
	LD	IX,REC_E
	CALL	PRIDEC
	POP	IX
	CALL	OUTLIN
	DEFB	"Received "
REC_B	DEFB	"     "
	DEFB	" byte(s).",13
	DEFB	"Found "
REC_E	DEFB	"     "
	DEFB	" error(s).",13,0
	RET
;
EX_L	POP	BC
BREAK2	LD	A,7
	OUT	(#FE),A
RBREAK	CALL	OUTLIN
	DEFB	"--- B R E A K ---",13,0
	RET
;
RECE_SCR
	CALL	OUTLIN
	DEFB	"Receive to screen. "
	DEFB	"Press a key for ready.",13
	DEFB	0
	LD	A,3
	LD	(CHAN),A
	JP	CONTR1
;
ERSCR
	CALL	OUTLIN
	DEFB	"Receive error.",13,0
	RET
;
PRINTBUF
	LD	HL,BUFER_SCR
	LD	B,64
PRIB2
	LD	A,(HL)
	RST	#10
	INC	HL
	DJNZ	PRIB2
	RET
;
C_TRANSMIT
	LD	A,(SDEV)
	AND	A
	JP	Z,TRAN_DISC
	CP	1
	JP	Z,TRAN_MEM
	CP	2
	JP	Z,TRAN_SCR
	CALL	OUTLIN
	DEFB	"Not present.",13
	DEFB	0
	RET
TRAN_MEM
	CALL	OUTLIN
	DEFB	"Transmit code from addr: ",0
	CALL	READNU
	JR	Z,TRM1
	CALL	CONDEC
	LD	(TR_ST),HL
	CALL	OUTLIN
	DEFB	", length: ",0
	CALL	READNU
	RET	Z
	CALL	CONDEC
	LD	DE,(TR_ST)
	ADD	HL,DE
	LD	(TR_END),HL
	CALL	OUTLIN
	DEFB	13
	DEFB	"Please	wait.",13,0
	CALL	TRANSMIT
	CALL	OUTLIN
	DEFB	"Transmiting: OK",13,0
TRM1	RET
;
CONDEC
	PUSH	IX
	LD	HL,#0000
	LD	D,#00
	LD	IX,BUFDEC
COND1	LD	A,(IX)
	SUB	#30
	CP	#0A
	JR	NC,ENDCOND
	LD	B,H
	LD	C,L
	ADD	HL,HL
	ADD	HL,HL
	ADD	HL,BC
	ADD	HL,HL
	LD	E,A
	ADD	HL,DE
	INC	IX
	JR	COND1
ENDCOND
	POP	IX
	RET
;
PRIDEC
	LD	DE,#2710
	CALL	PRID1
	LD	DE,#03E8
	CALL	PRID1
	LD	DE,#0064
	CALL	PRID1
	LD	DE,#000A
	CALL	PRID1
	LD	A,L
	ADD	A,#30
	LD	(IX),A
	RET
;
PRID1	XOR	A
PRID2	INC	A
	SBC	HL,DE
	JR	NC,PRID2
	ADD	HL,DE
	CP	C
	RET	Z
	DEC	C
	ADD	A,#2F
	LD	(IX),A
	INC	IX
	RET
;
CLS_BUF
	LD	HL,BUFER
	LD	DE,BUFER+1
	LD	BC,#3FFF
	LD	(HL),0
	LDIR
	RET
;
TRAN_DISC
	CALL	OUTLIN
	DEFB	"Transmit file:	",0
	LD	HL,#5CDD
	CALL	READLN
	RET	Z
	CALL	OUTLIN
	DEFB	" TYPE:	",0
	CALL	KBD
	CP	13
	RET	Z
	RST	#10
	LD	HL,#5CDD+8
	LD	(HL),A
	LD	C,#0A
	CALL	DOS
	BIT	7,C
	JP	NZ,EPS1
	PUSH	BC
	CALL	OUTLIN
	DEFB	13
	DEFB	"Loading: ",0
	CALL	PRINT_FCB
	CALL	OUTLIN
	DEFB	" for transmit.	Please Wait.",13,0
	POP	BC
	LD	A,C
	LD	C,8
	CALL	DOS
	LD	HL,#5CDD
	LD	(TR_ST),HL
	LD	HL,#5CDD+15
	LD	(TR_END),HL
	CALL	TRANSMIT
	LD	A,(#5CDD+13)
	LD	(MANYSEC),A
	LD	A,1
	LD	(COUNNUM),A
	LD	A,16
	LD	(HOW2),A
	LD	A,#40
	LD	(HOW1),A
	LD	HL,(#5CDD+14)
	LD	(#5CF4),HL
LOOPTR
	CALL	CLS_BUF
	LD	A,0
MANYSEC	EQU	$-1
	AND	A
	JP	Z,END_TR
	CP	64
	JR	C,OST
	SUB	64
	LD	(MANYSEC),A
CONTLOA
	LD	BC,#4005
HOW1	EQU	$-1
	LD	HL,BUFER
	LD	(BUFCOU),HL
	LD	DE,(#5CF4)
	CALL	DOS
	LD	B,16
HOW2	EQU	$-1
REPTR
	PUSH	BC
	LD	HL,BUFER
BUFCOU	EQU	$-2
	LD	(TR_ST),HL
	LD	DE,1024
	ADD	HL,DE
	LD	(TR_END),HL
	LD	(BUFCOU),HL
	CALL	TRANSMIT
	LD	A,0
COUNNUM	EQU	$-1
	LD	L,A
	LD	H,0
	PUSH	AF
	PUSH	IX
	LD	IX,BUFDEC
	CALL	PRIDEC
	POP	IX
	POP	AF
	INC	A
	LD	(COUNNUM),A
	LD	HL,(BUFDEC+3)
	LD	(BBB),HL
	LD	A,23
	LD	(SCROLL_CNT),A
	CALL	OUTLIN
	DEFB	"Block #"
BBB	DEFB	"  "
	DEFB	" transmiting.",13,0
	CALL	LFB4B
	JP	Z,EX_L
	POP	BC
	DJNZ	REPTR
	JP	LOOPTR
OST
	LD	(HOW1),A
	SRL	A
	JR	NC,COST1
	INC	A
COST1
	SRL	A
	JR	NC,COST
;ZER
	INC	A
COST
;	AND	A
;	JR	Z,CZER
	LD	(HOW2),A
	XOR	A
	LD	(MANYSEC),A
	JP	CONTLOA
;
END_TR
	CALL	OUTLIN
	DEFB	"End of	transmit.",13,0
	RET

EPS1
	CALL	OUTLIN
	DEFB	13
	DEFB	"File not found.",13,0
	LD	HL,0
	LD	(#5D0F),HL
	RET
;
TRAN_SCR
	CALL	OUTLIN
	DEFB	"Transmit text.	Enter text.",13
	DEFB	0
	LD	A,63
	LD	(RD1),A
	DEC	A
	LD	(RD2),A
	LD	HL,BUFER_SCR
	CALL	READLN
	JR	Z,NOTEXT
	LD	HL,BUFER_SCR
	LD	(TR_ST),HL
	LD	HL,BUFER_SCR+64
	LD	(TR_END),HL
	CALL	TRANSMIT
NOTEXT	LD	A,8
	LD	(RD1),A
	DEC	A
	LD	(RD2),A
	RET
;
C_DEVICE
	LD	A,0
SDEV	EQU	$-1
	AND	A
	JR	Z,SET_1
	CP	1
	JR	Z,SET_2
	CP	2
	JR	Z,SET_3
SET_0  ;DISC
	XOR	A
	LD	(SDEV),A
	LD	HL,TXT_DISC
CON_DEV
	LD	DE,SETDEV
	LD	BC,7
	PUSH	BC
	PUSH	HL
	LDIR
	POP	HL
	POP	BC
	LD	DE,SELECTED
	LDIR
	CALL	OUTLIN
	DEFB	"Selected device: "
SELECTED
	DEFB	"	",13,0
	RET
;
SET_1  ;MEMORY
	INC	A
	LD	(SDEV),A
	LD	HL,TXT_MEMORY
	JR	CON_DEV
;
SET_2  ;SCREEN
	INC	A
	LD	(SDEV),A
	LD	HL,TXT_SCREEN
	JR	CON_DEV
;
SET_3  ;PRINTER
	INC	A
	LD	(SDEV),A
	LD	HL,TXT_PRINTER
	JR	CON_DEV
;
C_BAUD
	LD	A,#96
CH_BAUD	EQU	$-1
	CP	#1E
	JR	Z,S600
	CALL	BAUD1200
	LD	HL,TXT_1200
S0	LD	DE,SETBAUD
	LD	BC,4
	PUSH	DE
	PUSH	BC
	LDIR
	POP	BC
	POP	HL
	LD	DE,MESS2
	LDIR
	CALL	OUTLIN
	DEFB	"Selected baudrate: "
MESS2	DEFB	"    ",13,0
	RET
S600
	CALL	BAUD600
	LD	HL,TXT_600
	JR S0
;
C_PARITY
	LD	A,#0A
CH_PAR	EQU	$-1
	CP	9
	JR	Z,SODD
	CALL	PAREVEN
	LD	HL,TXT_EVEN
S1	LD	DE,SETPAR
	LD	BC,4
	PUSH	DE
	PUSH	BC
	LDIR
	POP	BC
	POP	HL
	LD	DE,MESS1
	LDIR
	CALL	OUTLIN
	DEFB	"Selected parity: "
MESS1	DEFB	"    ",13,0
	RET
SODD
	CALL	PARODD
	LD	HL,TXT_ODD
	JR S1
;
PRINT_MENU
	CALL	OUTLIN
	DEFB	#0C
	DEFB	"Logged	drive: A"
LOGGEDTXT EQU $-1
	DEFB	13
	DEFB	"Baudrate: 600 "
SETBAUD	EQU	$-4
	DEFB	13
	DEFB	"Parity: ODD "
SETPAR	EQU	$-4
	DEFB	13
	DEFB	"Device: DISC	"
SETDEV	EQU	$-7
	DEFB	13,13
	DEFB	"Transmit   Receive   Auto check   Quit",13
	DEFB	"Catalog   load	Font   Help   teSt line",13
	DEFB	0
	RET
;
KEY_CHECK
	CALL	OUTLIN
	DEFB	#0D
	DEFB	"->"
	DEFB	0
	CALL	KBD
	RST	#10
	CALL	OUTLIN
	DEFB	13,0
	LD	HL,I_KEYS
	LD	B,LIKEYS
IKL1	CP	(HL)
	INC	HL
	JR	Z,IKL2
	INC	HL
	INC	HL
	DJNZ	IKL1
	RST	8
	DEFB	#FE
IKL2	LD	A,(HL)
	INC	HL
	LD	H,(HL)
	LD	L,A
	JP	(HL)
;
C_QUIT
	LD	SP,0000
BASIC_SP	EQU	$-2
	LD	HL,0000
SAV_ERRSP	EQU	$-2
	LD	(#5C3D),HL
	EXX
	POP	HL
	EXX
	RET
;
PRINT_FCB
	LD	HL,#5CDD
	LD	B,8
PRINT_FCB1
	LD	A,(HL)
	RST	#10
	INC	HL
	DJNZ	PRINT_FCB1
	RET
;
LOGGED
	LD	A,0
DR	EQU	$-1
	AND	A
	JR	Z,SET1
	XOR	A
CONDR
	LD	(DR),A
	LD	(#5D19),A
	PUSH	AF
	ADD	A,"A"
	LD	(LOGGEDTXT),A
	POP	AF
	LD	C,1
	CALL	DOS
	RET
SET1
	LD	A,1
	JR	CONDR
LOAD_FONT
	CALL	OUTLIN
	DEFB	"Name file: ",0
	LD	HL,#5CDD
	CALL	READLN
	RET	Z
	LD	A,"C"
	LD	(#5CDD+8),A
	LD	HL,FONT
	LD	DE,#200
	LD	A,3
	LD	C,#0E
	JP	DOS
;
READLN_END
	LD	A,C
	OR	A
	RET
;
READLN	PUSH	HL
	LD	E,L
	LD	D,H
	INC	DE
	LD	(HL)," "
	LD	BC,7
RD2	EQU	$-2
	LDIR
	POP	HL
READL1	CALL	KBD
	CP	13
	JR	Z,READLN_END
	CP	12
	JR	Z,RDLDEL
	CP	" "
	JR	C,READL1
	LD	B,A
	LD	A,C
	CP	8
RD1	EQU	$-1
	JR	Z,READL1
	LD	A,B
	RST	#10
	LD	(HL),A
	INC	HL
	INC	C
	JR	READL1
RDLDEL	LD	A,C
	OR	A
	JR	Z,READL1
	DEC	C
	DEC	HL
	LD	(HL)," "
	PUSH	HL
	LD	HL,TTY_X
	DEC	(HL)
	LD	A," "
	RST	#10
	DEC	(HL)
	DEC	(IX+CSRX)
	POP	HL
	JR	READL1
;
READNU_END
	INC	HL
	LD	(HL),#40
	LD	A,C
	OR	A
	RET
;
READNU
	LD	HL,BUFDEC
	PUSH	HL
	LD	E,L
	LD	D,H
	INC	DE
	LD	(HL)," "
	LD	BC,4
	LDIR
	POP	HL
READN1	CALL	KBD
	CP	13
	JR	Z,READNU_END
	CP	12
	JR	Z,RDNDEL
	CP	"0"
	JR	C,READN1
	CP	"9"+1
	JR	NC,READN1
	LD	B,A
	LD	A,C
	CP	5
	JR	Z,READN1
	LD	A,B
	RST	#10
	LD	(HL),A
	INC	HL
	INC	C
	JR	READN1
RDNDEL	LD	A,C
	OR	A
	JR	Z,READN1
	DEC	C
	DEC	HL
	LD	(HL)," "
	PUSH	HL
	LD	HL,TTY_X
	DEC	(HL)
	LD	A," "
	RST	#10
	DEC	(HL)
	DEC	(IX+CSRX)
	POP	HL
	JR	READN1
;
AUTO
	CALL	OUTLIN
	DEFB	"Auto check not	present.",13
	DEFB	0
;	LD	HL,#5CDD
;	CALL	READLN
;	RET	Z
	RET
;
C_CAT	LD	C,7
	LD	A,2
	JP	DOS
;
HL2H
	LD	A,H
	CALL	A2H
	LD	A,L
A2H
	PUSH	AF
	RRCA
	RRCA
	RRCA
	RRCA
	CALL	NIB
	POP	AF
NIB	AND	#0F
	ADD	A,#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-DATA
	DEFB	0
CSRY	EQU	$-DATA
	DEFB	0
;
TXT_600	DEFB	"600 "
TXT_1200 DEFB	"1200"
TXT_ODD	DEFB	"ODD "
TXT_EVEN DEFB	"EVEN"
TXT_DISC DEFB	"DISC	"
TXT_MEMORY DEFB	"MEMORY	"
TXT_SCREEN DEFB	"SCREEN	"
TXT_PRINTER DEFB "PRINTER"
BUFDEC	DEFS	6
BUFER_SCR DEFS 64
;
BAUD600	LD	A,#02		;wybor 600
	LD	(LFC8E),A
	LD	A,#04
	LD	(LFCA3),A
	LD	A,#02
	LD	(LFBED),A
	LD	A,#F5
	LD	(LFBF4),A
	LD	A,#81
	LD	(LFC00),A
	LD	A,#CD
	LD	(LFBFA),A
	LD	(LFC06),A
	LD	A,#B9
	LD	(LFC0C),A
	LD	A,#96
	LD	(CH_BAUD),A
	RET
;
BAUD1200
	LD	A,#01		;wybor 1200
	LD	(LFC8E),A
	LD	A,#02
	LD	(LFCA3),A
	LD	A,#01
	LD	(LFBED),A
	LD	A,#14
	LD	(LFBF4),A
	LD	A,#46
	LD	(LFC00),A
	LD	A,#3A
	LD	(LFBFA),A
	LD	(LFC06),A
	LD	A,#7D
	LD	(LFC0C),A
	LD	A,#1E
	LD	(CH_BAUD),A
	RET
;
PARODD	LD	A,#E4		;wybor ODD
	LD	(LFC71),A
	LD	A,#EC
	LD	(LFC74),A
	LD	A,#EA
	LD	(LFBD6),A
	LD	A,#E2
	LD	(LFBDD),A
	LD	A,#0A
	LD	(CH_PAR),A
	RET
;
PAREVEN
	LD	A,#E4		;wybor EVEN
	LD	(LFC74),A
	LD	A,#EC
	LD	(LFC71),A
	LD	A,#EA
	LD	(LFBDD),A
	LD	A,#E2
	LD	(LFBD6),A
	LD	A,#09
	LD	(CH_PAR),A
	RET
;
;	---- RECEIVE ----
;
RECEIVE
	XOR	A
	OUT	(#FE),A
	DI		;w HL -	s kakogo adresa	prinimatx
	LD	B,#00
	CALL	LFB55	;lowit piloton
	CALL	LFB64
;HL=skolxko prinql
;BC=skolxko o}ibok
	LD	A,7
	OUT	(#FE),A
	AND	A
	RET
;
;
LFB4B	PUSH	BC	;opros probela
	LD	BC,#7FFE
	IN	A,(C)
	BIT	0,A
	POP	BC
	RET
;
LFB55	CALL	LFB4B	;Opros SPACE
	RET	Z
	IN	A,(PORT)
	AND	#80
	CP	E
	JR	Z,LFB55
	LD	E,A
	DJNZ	LFB55
	RET		;wyhod esli byl	pilot ili signal
;
;w HL -	s kakogo adresa	priem
;
LFB64	PUSH	IX
	PUSH	IY
	PUSH	HL
	POP	IX
	LD	IY,#0000
LFB6F	PUSH	HL
	LD	HL,#0000     ;LEN
	LD	BC,#0000     ;ERRORS
LFB76	LD	D,#80
	IN	A,(PORT)
	AND	#80
LFB7C	LD	E,A
	LD	B,#00
LFB7F	IN	A,(PORT)
	AND	#80
	CP	E
	JR	NZ,LFB97
	DJNZ	LFB7F
	POP	HL
	PUSH	IY
	POP	BC
	PUSH	IX
	POP	DE
	POP	IY
	POP	IX
	SBC	HL,DE
	EI
	RET
;
LFB97	SLA	D
	JP	C,LFB7C
	LD	A,#E9
	CP	B
	JP	P,LFBAF
	XOR	A
	CP	C
	JP	NZ,LFBC4
	LD	C,#01
	CALL	LFBEC
	JP	LFB76
;
LFBAF	XOR	A
	CP	C
	JP	Z,LFB76
	INC	HL
	CALL	LFBF8
	LD	A,#09
	CP	L
	JP	Z,LFBD4
	SCF
	RR	H
	JP	LFB76
;
LFBC4	INC	HL
	CALL	LFC04
	LD	A,#09
	CP	L
	JP	Z,LFBDB
	AND	A
	RR	H
	JP	LFB76
;
LFBD4	XOR	A
	OR	H
LFBD6	JP	PE,LFBE2
	JR	LFBE8
;
LFBDB	XOR	A
	OR	H
LFBDD	JP	PO,LFBE2
	JR	LFBE8
;
LFBE2	POP	HL
	LD	(HL),A
	INC	HL
	JP	LFB6F
;
LFBE8	INC	IY
	JR	LFBE2
;
LFBEC	LD	B,#01
LFBED	EQU	$-1
LFBEE	CALL	LFC10
	DJNZ	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